<script src="<?php echo js_link('jquery.js');?>"></script>
<!-- start content-outer ......................START -->
<div id="content-outer">
<!-- start content -->
<div id="content">

	<!--  start page-heading -->
	<div id="page-heading">
		<h1>Home</h1>
	</div>
	<!-- end page-heading -->

	<table border="0" width="100%" cellpadding="0" cellspacing="0" id="content-table">
	<tbody><tr>
		<th rowspan="3" class="sized"><img src="<?php ECHO img_link('shared/side_shadowleft.jpg')?>" width="20" height="300" alt=""></th>
		<th class="topleft"></th>
		<td id="tbl-border-top">&nbsp;</td>
		<th class="topright"></th>
		<th rowspan="3" class="sized"><img src="<?php ECHO img_link('shared/side_shadowright.jpg')?>" width="20" height="300" alt=""></th>
	</tr>
	<tr>
		<td id="tbl-border-left"></td>
		<td valign="top">
		<!--  start content-table-inner ...................... START -->
		<div id="content-table-inner">
		
			<!--  start table-content  -->
			<div class="newcust"><a href="<?php echo base_url().'customer/add/';?>" target="_blank" class="new_button" title="New Customer">New Customer</a></div>
			<span class="sercust"><div class="search_button" title="Search Customers">Search Customers</div></span>
			<script>
				function search()
				{
					window.location="<?php echo base_url();?>customer/?name="+$("#name").val()+"&passport="+$("#passport").val()+"&agent="+$("#agent").val();
				}
			</script>
			<form method="get" action="" onsubmit="search(); return false;">
			<table border="0" cellpadding="7" cellspacing="0">

              <tbody>
              <tr>
              	
                <td align="left">Name:</td>
                <td align="left"><input name="textfield" type="text" class="field" id="name" size="26" value="<?php echo (isset($_GET['name']) ? $_GET['name'] : '');?>"></td>
                <td align="left">NRIC/FIN/Passport No.:</td>
                <td align="left"><input name="textfield6" type="text" class="field" id="passport" value="<?php echo (isset($_GET['passport']) ? $_GET['passport'] : '');?>" size="40"></td>
                <td align="left">Agent</td>
                <td align="left">
                	<select name="agent" id="agent">
                		<option value="">--All--</option>
                	<?php foreach($agents as $ag):?>
                		<option <?php echo(isset($_GET['agent']) && $_GET['agent']==$ag->user_id ? 'selected="selected"' : '')?> value="<?php echo $ag->user_id;?>"><?php echo $ag->username;?></option>
                	<?php endforeach;?>
                	</select>
                </td>
                <td><button class="large button red">Search</button></td>
              </tr>
            </tbody>
            </table>
            </form>
			<br>
			<table border="1" cellpadding="7" cellspacing="0" style="border-collapse:collapse;" bordercolor="#CCCCCC" ;="">
              <tbody><tr>
                <td class="table-title">Select</td>
                <td width="40" align="left" class="table-title">Title</td>
                <td width="260" align="left" class="table-title">Customer Name</td>
                <td width="100" align="left" class="table-title">Date of Birth</td>
                <td width="130" align="left" class="table-title">NRIC/FIN/Passport No.</td>
                <td width="300" align="left" class="table-title">Occupation</td>
                <?php if($_SESSION['_user']['group_id']==1):?>
                <td class="table-title">Agent</td>
                <?php endif;?>
                <td width="100" align="center" class="table-title">Action</td>
              </tr>
              <?php 
              foreach($customers as $customer):
              ?>
              <tr>
                <td><a href="<?php echo base_url().'customer/select/'.$customer->id;?>">Select</a></td>
                <td align="left"><?php echo $customer->title;?></td>
                <td align="left"><a href="<?php echo base_url().'customer/edit/'.$customer->id;?>"><?php echo $customer->fullname;?></a></td>
                <td align="left"><?php echo date('m/d/Y',strtotime($customer->date_of_birth));?></td>
                <td align="left"><?php echo $customer->passport_no;?></td>
                <td align="left"><?php echo $customer->occupation.$customer->create_by;?></td>
                <?php if($_SESSION['_user']['group_id']==1):?>
                <td>
                	<?php 
                	$CI	=& get_instance();
                	$CI->load->model('user_model');
                	$aq=$this->user_model->get_by(array('user_id' => $customer->create_by));
                	//echo $CI->db->last_query();
                	//print_r($aq);
                	echo ($aq ? $aq->username : 'admin');
                	?>
                <?php endif;?>
                </td>
                <td align="center"><a href="<?php echo base_url().'customer/edit/'.$customer->id;?>">Edit</a>&nbsp;|&nbsp;<a onclick="return confirm('Are you ok?');return false;" href="<?php echo base_url().'customer/del/'.$customer->id;?>">Delete</a></td>
              </tr>
              <?php 
              endforeach;
              ?>
            </tbody></table>
			<div class="clear"></div>
		</div>
		<!--  end content-table-inner ......................END  --></td>
		<td id="tbl-border-right"></td>
	</tr>
	<tr>
		<th class="sized bottomleft"></th>
		<td id="tbl-border-bottom">&nbsp;</td>
		<th class="sized bottomright"></th>
	</tr>
	</tbody></table>
	<?php echo $pagnav;?>
	<div class="clear">&nbsp;</div>

</div>
<!--  end content -->